package com.drakulo.games.ais.core;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

public class ResourceHelper {
	public static boolean enoughResourcesFor(Map<Resource, BigDecimal> costMap) {
		return enoughResourcesFor(costMap, GameData.getSelectedColony());
	}

	public static boolean enoughResourcesFor(
			Map<Resource, BigDecimal> costMap, Colony c) {
		if(Settings.NO_COST){
			return true;
		}
		Resource[] resources = Resource.values();
		for (Resource r : resources) {
			BigDecimal inStore = c.getResource(r);
			BigDecimal cost = costMap.get(r);
			if (cost == null) {
				// No value defined for this resource
				continue;
			}
			if (NumberHelper.inf(inStore, cost)) {
				// Not enought resource in the store
				return false;
			}
		}

		// That's OK!
		return true;
	}

	public static Map<Resource, BigDecimal> cloneMap(
			Map<Resource, BigDecimal> map) {
		Map<Resource, BigDecimal> newMap = new HashMap<Resource, BigDecimal>();
		for (Resource r : map.keySet()) {
			newMap.put(r, map.get(r));
		}
		return newMap;
	}

	public static boolean enoughSpaceFor(Map<Resource, BigDecimal> map, Colony c) {
		Resource[] resources = Resource.values();
		for (Resource r : resources) {
			BigDecimal space = c.getStorSpace(r);
			BigDecimal val = map.get(r);
			if (val == null) {
				// No value defined for this resource -> skip it
				continue;
			}
			if (NumberHelper.inf(space, val)) {
				// Not enought space
				return false;
			}
		}

		// That's OK!
		return true;
	}
}
